

package cn.shengchao.controler;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.StrUtil;
import cn.shengchao.examstar.teacher.acl.ports.message.TeacherInfo;
import cn.shengchao.examstar.teacher.acl.ports.repositories.ITeacherRepository;
import cn.shengchao.examstar.teacher.ohs.local.appservice.TeacherAppService;
import cn.shengchao.examstar.teacher.ohs.local.message.TeacherDetails;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.web.model.R;

import java.util.ArrayList;
import java.util.List;

@Tag(name = "老师")
@Slf4j
@RestController
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/teacher")
public class TeacherController {

    @Autowired
    private ITeacherRepository iTeacherRepository;

    @Autowired
    private TeacherAppService teacherAppService;

    @SaIgnore
    @GetMapping
    public List<TeacherInfo> getTeacherList(@RequestParam String ids) {
        log.info("获取老师列表:{}", ids);
        if (StrUtil.isEmpty(ids)) {
            return new ArrayList<>();
        }
        return iTeacherRepository.findByIds(ids.split(","));
    }

    @PutMapping("{teacherId}/show")
    public R updateShow(@PathVariable Long teacherId) {
        iTeacherRepository.updateShow(teacherId);
        return R.ok();
    }

    @SaIgnore
    @GetMapping("{teacherId}")
    public TeacherDetails getTeacherInfo(@PathVariable Long teacherId) {
        return teacherAppService.getTeacherInfo(teacherId);
    }

}
